Ext.define('NIM.view.AssetChange.HentiOperasiSite', {
      extend : 'Ext.panel.Panel',
      alias : 'widget.HentiOperasiSite',
      id : 'hentioperasisite',
      border : false,
      title : 'Henti Operasi Site',
      layout : 'fit',
      closable : true,
      layout : {
        type : 'border'
      },
      width : 1 * screen.width,
      height : 590,
      items : [{
            xtype : 'form',
            id : 'panelhentioperasisite',
            title : 'Henti Operasi Site Form',
            region : 'west',
            margin : '5 5 5 5',
            method : 'POST',
            url : './Services/AssetChange/Site/Change/Add',
            collapsible : true,
            collapsed : true,
            width : 600,
            items : [
                 {

	                  xtype : 'hiddenfield',
	                  cls : 'black',
	                  name : 'CHANGE_CATEGORY',
	                  value :'HENTI_OPERASI_SITE',
	                  margin : '5 10 5 25',
	                  labelWidth : 100 / 1366 * screen.width,
	                  width : 300 / 1366 * screen.width,
	                  fieldLabel : 'Site ID',
	                  msgTarget : 'title',
	                  allowBlank : true,
	                  validateBlank : false

                },
				{
	                  xtype : 'fieldcontainer',
	                  cls : 'black',
	                  margin : '10 10 10 10',
	                  fieldLabel : 'SITE ID',
	                  labelWidth : 130 / 1366 * screen.width,
	                  width : 325 / 1366 * screen.width,
	                  layout : 'hbox',
	                  items : [
	                     {
	                        xtype : 'textfield',
	                        id : 'hentioperasisiteid',
	                        name : 'SOURCE_SITE_ID',
	                        margin : '0 5 0 0',
	                        width : 135,
	                        hideLabel : true,
	                        allowBlank : false
	                        
	                      }, 
	                      {
	                        xtype : 'button',
	                        text : 'Browse',
	                        width : 50,
	                        handler : function() {
	                          openPopup("hentioperasisiteid", "hentioperasisitename");
	
	                       }}]
                }, 
                {
	                  xtype : 'textfield',
	                  fieldLabel : 'SITE NAME',
	                  id : 'hentioperasisitename',
	                  labelWidth : 130 / 1366 * screen.width,
	                  width : 325 / 1366 * screen.width,
	                  margin : '10 10 0 10',
	                  allowBlank : false
                  
                },
                {
	                  xtype : 'datefield',
	                  minDate : new Date(),
	                  fieldLabel : 'DATE',
	                  name : 'CHANGE_DATE',
	                  labelWidth : 130 / 1366 * screen.width,
	                  width : 325 / 1366 * screen.width,
	                  margin : '10 10 0 10',
	                  allowBlank : false
                  
                },  
                {
	                  xtype : 'combobox',
	                  fieldLabel : 'Reason',
	                  name : 'CR_ID',
	                  displayField : 'CHANGE_REASON',
	                  valueField : 'CR_ID',
	                  labelWidth : 130 / 1366 * screen.width,
	                  width : 325 / 1366 * screen.width,
	                  allowBlank : false,
	                  store : 'Administration.AssetChangeReason',
	                  margin : '15 10 0 10',
	                  listeners : {
		                    afterrender : function() {
		                      Ext.getStore('Administration.AssetChangeReason').removeAll();
		                      Ext.getStore('Administration.AssetChangeReason').getProxy().url = './Services/DataMaster/AssetChangeReason/List?CHANGE_CATEGORY=HENTI_OPERASI_SITE';
		                      Ext.getStore('Administration.AssetChangeReason').load();
		                    }
	                  }
                },
                {
		             xtype: 'fileuploadfield',
		             emptyText: 'Select a document to upload...',
		             name:'FILE',
		             fieldLabel: 'ATTACHMENT FILE',
		             buttonText: 'Browse',
		             labelWidth: 130/1366*screen.width,
		             width: 325/1366*screen.width,
		             margin:'10 10 0 10'
	            },
                {
                  xtype : 'button',
                  text : 'PROCESS',
                  margin : '25 10 10 10',
                  handler : function() {
                    this.up('form').getForm().submit({
                          waitMsg : 'Please Wait ....',
                          success : function(form, action) {
                        	  return_AssetChange(form, action,"assethentioperasisite");
                        	  refreshAssetChange('AssetChange.HentiOperasiSiteStore','./Services/AssetChange/Change/Detail/List?CHANGE_CATEGORY=HENTI_OPERASI_SITE');
                        	  
                        	  Ext.getStore('AssetDataMaster.AssetNonSac').getProxy().url = './Services/AssetChange/Asset/From/Site/List?site_id='+Ext.getCmp("hentioperasisiteid").getValue();
	              			  Ext.getStore('AssetDataMaster.AssetNonSac').load();
	              			  tempDataNE("assethentioperasisite","AssetDataMaster.AssetNonSac");
                          },
                          failure : function(form, action) {
                        	  return_AssetChange(form, action,"assethentioperasisite");
                        	  refreshAssetChange('AssetChange.HentiOperasiSiteStore','./Services/AssetChange/Change/Detail/List?CHANGE_CATEGORY=HENTI_OPERASI_SITE');
                        	  
                        	  Ext.getStore('AssetDataMaster.AssetNonSac').getProxy().url = './Services/AssetChange/Asset/From/Site/List?site_id='+Ext.getCmp("hentioperasisiteid").getValue();
	              			  Ext.getStore('AssetDataMaster.AssetNonSac').load();
	              			  tempDataNE("assethentioperasisite","AssetDataMaster.AssetNonSac");
                          }
                        });
                    
	                      
                      }

                }, 
                {
                  xtype : 'button',
                  text : 'RESET',
                  margin : '25 10 10 10',
                  handler : function() {
                    this.up('form').getForm().reset();
                  }
                },
                {
                	  xtype :'panel',
                	  id    :'assethentioperasisite',
                	  border: false,
                	  
                 }]

          }, 
          {
            xtype : 'gridpanel',
            region : 'center',
            id : 'tablehentioperasisite',
            height : 590,
            // width : 400,
            titleAlign : 'center',
            margin : '5 5 5 0',
            border : true,
            forceFit : true,
            columnLines : true,
            store : 'AssetChange.HentiOperasiSiteStore',
            selType : 'checkboxmodel',
            title : 'Henti Operasi Site',
            columns : [{dataIndex : 'change_category',text : 'CHANGE CATEGORY',align : 'left'},
                       {dataIndex : 'change_reason',text : 'REASON',align : 'left'},
                       {dataIndex : 'source_site_id',text : 'SOURCE SITE ID',align : 'left'},
                       { dataIndex : 'destination',text : 'DESTINATION',align : 'left'}, 
                       {
                      	    xtype: 'actioncolumn',
                      	    text : 'DOCUMENT',
                      	    align : 'center',
                      	    renderer: function (value, metadata, record) {
                      	    	var document = record.get('document');
                      	    	if (document=="null"){
                      	    		this.items[0].icon = '';
                      	    	}else{
                      	    		var typefile=document.split(".");
                      	    		 if (typefile[1]=="pdf"){ 
                      	    			 this.items[0].icon = 'images/pdf-icon.png'; 
                      	    		 }else if (typefile[1]=="docx" || typefile[1]=="doc"){
                      	    			 this.items[0].icon = 'images/Word-icon.png';  
                      	    		 }else if (typefile[1]=="xlsx" || typefile[1]=="xls"){ 
                      	    			 this.items[0].icon = 'images/Excel-icon.png';  
                      	    		 }
                      	    	}
                      	    },
                      	    items: [{
                      	        tooltip: 'Show Document',
                      	        handler: function (grid, rowIndex, colIndex) {
                      	        	openFIle(grid,rowIndex);
                      	        }
                      	    }]
                      	}],
            listeners : {
	              afterrender : function() {
	            	  refreshAssetChange('AssetChange.HentiOperasiSiteStore','./Services/AssetChange/Change/Detail/List?CHANGE_CATEGORY=HENTI_OPERASI_SITE');
	              },
	              
	              itemdblclick : function(grid, record) {
	            	  var change_id = record.get('change_id');
	            	  change_id_global = change_id;
	                		if(Ext.getCmp('panelhentioperasisite').hidden == true) Ext.getCmp('panelhentioperasisite').toggleCollapse(true);
	                		Ext.Ajax.request({
	                		    method: "GET",
	                		    dataType: "json",
	                		    url: "./Services/AssetChange/Change/Detail/"+change_id,
	                		    async: false	,
	                		    success: function(c) {
	                		    	var jsonResults= $.parseJSON(c.responseText);
	                		    	data = jsonResults.item[0];
	                		    	console.log (data);
	                		    	Ext.getCmp('panelhentioperasisite').getForm().setValues(data);
	                		        }
	                		    });
	            	  Ext.getStore('AssetDataMaster.AssetNonSac').removeAll();
                      Ext.getStore('AssetDataMaster.AssetNonSac').getProxy().url = './Services/AssetChange/Change/Details/List/'+change_id+'?start=0&limit=20';
                      Ext.getStore('AssetDataMaster.AssetNonSac').load();
                      ShowGridAsset("assethentioperasisite");      
	            	  	
	                }
              
            },

            dockedItems : [
                {
	                  xtype : 'pagingtoolbar',
	                  dock : 'bottom',
	                  store : 'AssetChange.HentiOperasiSiteStore',
	                  displayInfo : true
                },
                {
	                  xtype : 'toolbar',
	                  dock : 'top',
	                  items : [
	                  {
		                    xtype : 'textfield',
		                    fieldLabel : 'KEYWORD',
		                    id : 'keywordhentioperasisite',
		                    margin : '0 10 0 10',
		                    labelWidth : 60,
		                    enableKeyEvents : true,
		                    listeners : {
		                      keypress : function(form, e) {
		                        if (e.getKey() == 13) {
		                        	 var keyword = Ext.getCmp("keywordhentioperasisite").getValue();
		                        	 searchAssetChange('AssetChange.HentiOperasiSiteStore','Services/AssetChange/Change/Detail/List?CHANGE_CATEGORY=HENTI_OPERASI_SITE&keyword=',keyword);
		                        }
		
		                      }
		                    }
	                  }, 
	                  {
		                    xtype : 'button',
		                    text : 'SEARCH',
		                    id : 'searchhentioperasisite',
		                    margin : '0 30 0 0',
		                    handler : function() {
		                    	 var keyword = Ext.getCmp("keywordhentioperasisite").getValue();
	                        	 searchAssetChange('AssetChange.HentiOperasiSiteStore','Services/AssetChange/Change/Detail/List?CHANGE_CATEGORY=HENTI_OPERASI_SITE&keyword=',keyword);
		                   }
	                  },
	                  {
		                    xtype : 'button',
		                    text : 'ADD NEW',
		                    margin : '0 20 0 0',
		                    handler : function() {
		                      if (Ext.getCmp('panelhentioperasisite').hidden == true)
		                        Ext.getCmp('panelhentioperasisite').toggleCollapse(true);
		                   }
	
	                  }, 
	                  {
		                    xtype : 'button',
		                    text : 'DELETE',
		                    margin : '0 20 0 0'
	
	                  },
	                  {
		                    xtype : 'button',
		                    text : 'REFRESH',
		                    margin : '0 20 0 0',
		                    handler : function() {
		                    	refreshAssetChange('AssetChange.HentiOperasiSiteStore','./Services/AssetChange/Change/Detail/List?CHANGE_CATEGORY=HENTI_OPERASI_SITE');
		                    }
	                  }]
	                }
                ]

          }]
    });

